<?php include('CSRE_login_control.php') ?>

<?php require_once('Connections/CSRE_Connection.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE csre_client SET pri_email=%s, company_name=%s, csss_parent_id=%s, name=%s, phone=%s, fax=%s, adresse=%s, ville=%s, province=%s, zip=%s, country=%s WHERE `user`=%s",
                       GetSQLValueString($_POST['pri_email'], "text"),
                       GetSQLValueString($_POST['company_name'], "text"),
                       GetSQLValueString($_POST['csss_parent_id'], "int"),
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['phone'], "text"),
                       GetSQLValueString($_POST['fax'], "text"),
                       GetSQLValueString($_POST['adresse'], "text"),
                       GetSQLValueString($_POST['ville'], "text"),
                       GetSQLValueString($_POST['province'], "text"),
                       GetSQLValueString($_POST['zip'], "text"),
                       GetSQLValueString($_POST['country'], "text"),
                       GetSQLValueString($_POST['user'], "text"));

  mysql_select_db($database_CSRE_Connection, $CSRE_Connection);
  $Result1 = mysql_query($updateSQL, $CSRE_Connection) or die(mysql_error());

  $updateGoTo = "CSRE_CLSC_profile.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_Client = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Client = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_CSRE_Connection, $CSRE_Connection);
$query_Client = sprintf("SELECT * FROM csre_client WHERE `user` = '%s'", $colname_Client);
$Client = mysql_query($query_Client, $CSRE_Connection) or die(mysql_error());
$row_Client = mysql_fetch_assoc($Client);
$totalRows_Client = mysql_num_rows($Client);
?>


<?php include('CSRE_header.php'); ?>
	
	<div align="center">
		<span style="background-color:#FFFFFF;">
			<table class="base_table">
				<tr>
				<td valign="top" width="200">
					<?php include('CSRE_left_menu.php'); ?>
				</td>
				
				<td style="background-image:url('images/divider.gif'); background-repeat:repeat-y;"></td>
				
	
				<td valign="top">
				
					<table width="100%" style="text-align:left;" class="text">
						<tr valign="top">
							<td class="title_csre">
								Votre Compte
							</td>
						</tr>
						<tr>
							<td height="5">
							</td>
						</tr>
						<tr><td height="10"></td></tr>
						<tr>
							<td><form method="post" name="form1" action="<?php echo $editFormAction; ?>">
                              <table align="center" width="80%">
                                <tr valign="baseline">
                                  <td nowrap align="left">Email:</td>
                                  <td><input type="text" name="pri_email" class="text" value="<?php echo $row_Client['pri_email']; ?>" size="32"></td>
                                </tr>
                                <tr valign="baseline">
                                  <td nowrap align="left">Company Name:</td>
                                  <td><input type="text" name="company_name" class="text" value="<?php echo $row_Client['company_name']; ?>" size="32"></td>
                                </tr>
                                <tr valign="baseline">
                                  <td nowrap align="left">Name:</td>
                                  <td><input type="text" name="name" class="text" value="<?php echo $row_Client['name']; ?>" size="32"></td>
                                </tr>
                                <tr valign="baseline">
                                  <td nowrap align="left">Phone:</td>
                                  <td><input type="text" name="phone"class="text"  value="<?php echo $row_Client['phone']; ?>" size="32"></td>
                                </tr>
                                <tr valign="baseline">
                                  <td nowrap align="left">Fax:</td>
                                  <td><input type="text" name="fax" class="text" value="<?php echo $row_Client['fax']; ?>" size="32"></td>
                                </tr>
                                <tr valign="baseline">
                                  <td nowrap align="left">Adresse:</td>
                                  <td><input type="text" name="adresse" class="text" value="<?php echo $row_Client['adresse']; ?>" size="32"></td>
                                </tr>
                                <tr valign="baseline">
                                  <td nowrap align="left">Ville:</td>
                                  <td><input type="text" name="ville" class="text" value="<?php echo $row_Client['ville']; ?>" size="32"></td>
                                </tr>
                                <tr valign="baseline">
                                  <td nowrap align="left">Province:</td>
                                  <td><input type="text" name="province" class="text" value="<?php echo $row_Client['province']; ?>" size="32"></td>
                                </tr>
                                <tr valign="baseline">
                                  <td nowrap align="left">Zip:</td>
                                  <td><input type="text" name="zip" class="text" value="<?php echo $row_Client['zip']; ?>" size="32"></td>
                                </tr>
                                <tr valign="baseline">
                                  <td nowrap align="left">Country:</td>
                                  <td><input type="text" name="country" class="text" value="<?php echo $row_Client['country']; ?>" size="32"></td>
                                </tr>
                              </table>
							  <div id="botonera" align="right">
									<table cellpadding="5" cellspacing="5">
										<tr>
											<td>
												<button type="submit" name="login" class="submit_csre">
														<table cellpadding="0" cellspacing="0" style="background-image:url(login_bg.gif); background-repeat:repeat-x;">
															<tr>
																<td>
																	<img src="login_left.gif" />
																</td>
																<td>
																	<span style="font-family:Verdana, Helvetica, sans-serif; font-weight:bold; color:#FFFFFF;">
																		Enregister
																	</span>
																</td>
																<td>
																	<img src="login_right.gif">
																</td>
															</tr>
														</table>
													</button>
											</td>
										</tr>
									</table>
								</div>
							  <input type="hidden" name="MM_update" value="form1">
                              <input type="hidden" name="user" value="<?php echo $row_Client['user']; ?>">
                            </form>
						    <p>&nbsp;</p></td>
						</tr>
					</table>
				
				
					
				</td>
				</tr>
			</table>
		</span>
	</div>

<?php include('CSRE_footer.php'); ?>
<?php
mysql_free_result($Client);
?>